<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="com.lanou.bookstore.book.domain.Book" %>
<%@ page import="com.lanou.bookstore.cart.domain.Cart" %>
<%@ page import="com.lanou.bookstore.cart.domain.CartItem" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>购物车列表</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <style type="text/css">
        * {
            font-size: 11pt;
        }

        div {
            margin: 20px;
            border: solid 2px gray;
            width: 150px;
            height: 150px;
            text-align: center;
        }

        li {
            margin: 10px;
        }

        #buy {
            background: url(<c:url value='/images/all.png'/>) no-repeat;
            display: inline-block;

            background-position: 0 -902px;
            margin-left: 30px;
            height: 36px;
            width: 146px;
        }

        #buy:HOVER {
            background: url(<c:url value='/images/all.png'/>) no-repeat;
            display: inline-block;

            background-position: 0 -938px;
            margin-left: 30px;
            height: 36px;
            width: 146px;
        }
    </style>
</head>

<%-- <body>
<h1>购物车</h1>

<table border="1" width="100%" cellspacing="0" background="black">
   <tr>
       <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">
           <a href="javascript:alert('已清空购物车！');">清空购物车</a>
           &lt;%&ndash;<a href="/cart.action?method=clear">清空购物车</a>&ndash;%&gt;
       </td>
   </tr>
   <tr>
       <th>图片</th>
       <th>书名</th>
       <th>作者</th>
       <th>单价</th>
       <th>数量</th>
       <th>小计</th>
       <th>操作</th>
   </tr>

   <tr>
       <td><div><img src="<c:url value='/book_img/8758723-1_l.jpg'/>"/></div></td>
       <td>Java详解</td>
       <td>张孝祥</td>
       <td>39.9元</td>
       <td>2</td>
       <td>79.8元</td>
       <td><a href="javascript:alert('删除购物项成功！');">删除</a></td>
   </tr>
   <tr>
       <td><div><img src="<c:url value='/book_img/8991366-1_l.jpg'/>"/></div></td>
       <td>Java详解</td>
       <td>张孝祥</td>
       <td>39.9元</td>
       <td>2</td>
       <td>79.8元</td>
       <td><a href="javascript:alert('删除购物项成功！');">删除</a></td>
   </tr>
   <tr>
       <td><div><img src="<c:url value='/book_img/9265169-1_l.jpg'/>"/></div></td>
       <td>Java详解</td>
       <td>张孝祥</td>
       <td>39.9元</td>
       <td>2</td>
       <td>79.8元</td>
       <td><a href="javascript:alert('删除购物项成功！');">删除</a></td>
   </tr>
   <tr>
       <td><div><img src="<c:url value='/book_img/9317290-1_l.jpg'/>"/></div></td>
       <td>Java详解</td>
       <td>张孝祥</td>
       <td>39.9元</td>
       <td>2</td>
       <td>79.8元</td>
       <td><a href="javascript:alert('删除购物项成功！');">删除</a></td>
   </tr>

   <tr>
       <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">
           合计：319.2元
       </td>
   </tr>
   <tr>
       <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">
           <a id="buy" href="<c:url value='/jsps/order/desc.jsp'/>"></a>
       </td>
   </tr>
</table>
 </body>--%>

<%--<body>--%>
<%--<h1>购物车</h1>--%>

<%--<table border="1" width="100%" cellspacing="0" background="black">--%>
    <%--<tr>--%>
        <%--<td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">--%>
            <%--<a href="/cart.action?method=clear">清空购物车</a>--%>
        <%--</td>--%>
    <%--</tr>--%>
    <%--<tr>--%>
        <%--<th>图片</th>--%>
        <%--<th>书名</th>--%>
        <%--<th>作者</th>--%>
        <%--<th>单价</th>--%>
        <%--<th>数量</th>--%>
        <%--<th>小计</th>--%>
        <%--<th>操作</th>--%>
    <%--</tr>--%>
    <%--<tr>--%>
            <%--<%--%>
            <%--List<Book> books = (List<Book>) request.getAttribute("users");--%>
            <%--int i=0;--%>
            <%--for (Book book : books) {--%>
                <%--i++;--%>
                <%--%>--%>
    <%--<tr>--%>
        <%--<td><%=book.getImage()%></td>--%>
        <%--<td><%=book.getBname()%></td>--%>
        <%--<td><%=book.getAuthor()%></td>--%>
        <%--<td><%=book.getPrice()%></td>--%>
        <%--&lt;%&ndash;<td><%=items.getCount()%></td>&ndash;%&gt;--%>
        <%--<td><span>小计</span></td>--%>
        <%--<td><a href="/cart.action?bid=<%=book.getBid()%>&method=del">删除</a></td>--%>
    <%--</tr>--%>
    <%--<%--%>
        <%--}--%>
    <%--%>--%>
    <%--</tr>--%>
    <%--<tr>--%>
        <%--<td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">--%>
            <%--合计：--%>
        <%--</td>--%>
    <%--</tr>--%>
    <%--<tr>--%>
        <%--<td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">--%>
            <%--<a id="buy" href="<c:url value='/jsps/order/desc.jsp'/>"></a>--%>
        <%--</td>--%>
    <%--</tr>--%>
<%--</table>--%>
<%--</body>--%>

<h1>购物车</h1>

<table border="1" width="100%" cellspacing="0" background="black">
    <tr>
        <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">
            <a href="<%=request.getContextPath()%></cart.do>?method=clear">清空购物车</a>
        </td>
    </tr>
    <tr>
        <th>图片</th>
        <th>书名</th>
        <th>作者</th>
        <th>单价</th>
        <th>数量</th>
        <th>小计</th>
        <th>操作</th>
    </tr>
    <%
        Cart cart = (Cart) application.getAttribute("cart");
        double totalAll = 0.0;

        if (cart != null) {
            List<CartItem> cartItems = cart.getItems();
            for (CartItem cartItem : cartItems) {
                Integer count = cartItem.getCount();
                int c = 0;
                try {
                    c = count;
                } catch (Exception e) {
                    e.printStackTrace();
                }
                double price = cartItem.getBook().getPrice();
                double total = price * c;
                String url=cartItem.getBook().getImage();
                String bid=cartItem.getBook().getBid();

    %>
    <tr>
        <td>
            <%--<div><img src="<c:url value='/book_img/<%=cartItem.getBook().getImage()%>'/>"/></div>--%>
            <div><img src="<%=url%>"/></div>
        </td>
        <td><%=cartItem.getBook().getBname()%>
        </td>
        <td><%=cartItem.getBook().getAuthor()%>
        </td>
        <td><%=cartItem.getBook().getPrice()%>元</td>
        <td><%=cartItem.getCount()%>
        </td>
        <td><%=total%>元</td>
        <td><a href="<c:url value='/cart.do'/>?bid=<%=bid%>&method=del">删除</a></td>
    </tr>

    <%
                totalAll += total;
            }
        }

    %>
    <tr>
        <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">
            合计：<%=totalAll%>元
        </td>
    </tr>
    <tr>
        <td colspan="7" align="right" style="font-size: 15pt; font-weight: 900">
            <a id="buy" href="<c:url value='/order.do'/>"></a>
        </td>
    </tr>

</table>
</body>
</html>

</html>
